package top.canyue.word_range_service.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.canyue.word_range.pojo.dto.PageDTO;
import top.canyue.word_range.pojo.dto.WordBookDto;
import top.canyue.word_range.pojo.po.WordMapping;
import top.canyue.word_range.pojo.query.WordQuery;
import top.canyue.word_range.pojo.vo.WordBookVo;
import top.canyue.word_range.result.Result;
import top.canyue.word_range_service.service.WordBookService;
import top.canyue.word_range_service.service.WordMappingService;

import java.util.List;

/**
 * 词书相关接口
 */
@RestController
@RequestMapping("/apiV1/wordBook")
@RequiredArgsConstructor
public class WordBookController {
    final WordBookService wordBookService;
    private final WordMappingService wordMappingService;

    /**
     * 添加词书
     */
    @PutMapping
    public Result<Object> addWordBook(@RequestHeader String JWT, @RequestBody WordBookDto wordBookDto){
        return wordBookService.addWordBook(wordBookDto);
    }

    /**
     * 基于ID获取词书信息
     * @param id 词书ID
     */
    @GetMapping("/{id}")
    public Result<WordBookVo> getWordBookById(@RequestHeader String JWT, @PathVariable String id){
        return wordBookService.getWordBookById(id);
    }

    /**
     * 更新词书信息
     */
    @PostMapping
    public Result<Object> updateWordBook(@RequestHeader String JWT, @RequestBody WordBookDto wordBookDto){
        return wordBookService.updateWordBook(wordBookDto);
    }

    /**
     * 获取词书ID和词书名的列表
     * <p>先是这么实现，后续数据量大了再更新</p>
     */
    @GetMapping("/allBookInfo")
    public Result<List<WordBookVo>> getAllBookInfo(@RequestHeader String JWT){
        return wordBookService.getAllBookInfo();
    }

    /**
     * 分页获取词书下的所有词
     */
    @GetMapping("/allWord")
    public PageDTO<WordMapping> getAllWord(@RequestHeader String JWT, WordQuery wordQuery){
        return wordMappingService.getAllWordById(wordQuery);
    }

}
